//
//  YJMMainTableViewController.swift
//  Weibo
//
//  Created by 杨军民 on 16/7/18.
//  Copyright © 2016年 杨军民. All rights reserved.
//

import UIKit

class YJMMainTableViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        

        //设置自定义tabBar
        let mainTabBar = YJMMainTabBar()
        
        //定义闭包和传递
        mainTabBar.composeCallBlock = { () -> Void in
            print("hahha ")
        }
    
        
        //KVC
        self.setValue(mainTabBar, forKeyPath: "tabBar")
        
        addChildviewcontroller()
    }
    //private：私有
   private func addChildviewcontroller() {
        //首页
        let HomeController = YJMHomeTableViewController()
        self.addChildViewController(HomeController, title: "首页", image: "tabbar_home")
        
        //消息
        let messageController = YJMMessageTableViewController()
        self.addChildViewController(messageController, title: "消息", image: "tabbar_message_center")
      
        //发现
        let findController = YJMFindTableViewController()
        self.addChildViewController(findController, title: "发现", image: "tabbar_discover")
        
        //我
        let myselfController = YJMMyselfTableViewController()
        self.addChildViewController(myselfController, title: "我", image: "tabbar_profile")
    }
    
    //抽取控件方法
    func addChildViewController(controller:UIViewController , title : String , image : String) {
        //设置标题
        controller.title = title
        //设置选中的字体颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor .orangeColor()], forState: UIControlState.Selected)
        
        /*----------------------------------------------------------*/
        
        //设置图片
        controller.tabBarItem.image = UIImage.init(named: image)
        //拼接图片
        let selectedImage = image + "_selected"
        //设置选中的图片
        /*
        imageWithRenderingMode : 渲染模式的图像
        AlwaysOriginal : 原创
        */
       controller.tabBarItem.selectedImage = UIImage(named: selectedImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
    }

}
